package ygw.study.tool;

import org.apache.commons.io.FileUtils;
import org.jasypt.properties.PropertyValueEncryptionUtils;
import org.jasypt.util.text.BasicTextEncryptor;

import java.io.File;
import java.io.IOException;

/**
 * <p>
 * 配置文件遍历加解密
 * </p>
 * <p>
 * Copyright:.All rights reserved.
 * </p>
 * <p>
 * Company:Zsoft
 * </p>
 * <p>
 * CreateDate: 2023/8/2
 * </p>
 * 
 * @author YuGongWen
 * @history Mender: YuGongWen；Date: 2023/8/2；
 */
public class ConfigUtils {
    private static BasicTextEncryptor textEncryptor = new BasicTextEncryptor();

    static {
        textEncryptor.setPassword("$gov.platform.core.Configuration$");
    }

    /**
     * 加密
     * @param value
     */
    public static String encryptValue(String value) {
        return PropertyValueEncryptionUtils.encrypt(value, textEncryptor);
    }
    /**
     * 解密
     * @param value
     * @return
     */
    public static String decryptValue(String value) {
        return PropertyValueEncryptionUtils.decrypt(value, textEncryptor);
    }


    public static void main(String[] args) throws IOException {

        long start = System.currentTimeMillis();
        String toString = FileUtils.readFileToString(new File("C:\\Users\\yugongwen\\Desktop\\2222222222222\\aaa.txt"), "UTF-8");
//        System.out.println("（代码标识号： GZ-ZHBS-5376223785392743）toString = " + toString);

        long end = System.currentTimeMillis();
        
        System.out.println("（代码标识号： GZ-ZHBS-5976223785992743）end = " + (end-start)/1000);
        
        

        String value = ConfigUtils.encryptValue(toString);
//        System.out.println("（代码标识号： GZ-ZHBS-5776223785792743）value = " + value);

        end = System.currentTimeMillis();
        System.out.println("（代码标识号： GZ-ZHBS-5976223785992743）end = " + (end-start)/1000);

        start = System.currentTimeMillis();
        String base64Str = MyBase64Utils.getBase64Str(toString);
        end = System.currentTimeMillis();
        System.out.println("（代码标识号： GZ-ZHBS-3333333333）end = " + (end-start)/1000);




    }
    
    
    
    
    
    
    
    
    
    
}